'''
Created on Mar 21, 2013

@author: Jason
'''

from SimPy.Simulation import *
from Globals import *

class Server(Process):
    Servers = []
    SrvRate = 2.0
    priorityQueue = []
    bestEffortQueue = []
    
    def __init__(self):
        Process.__init__(self)
        Server.Servers.append(self)
        print 'Server Created'
        
    def Run(self):
        while 1:
            yield passivate,self
            
            if Server.priorityQueue != []:
                #process a packet from the priority queue
                packet = Server.priorityQueue.pop(0)
                print 'processing from priority'
            elif Server.bestEffortQueue != []:
                #process a packet from the bestEffortQueue
                packet = Server.bestEffortQueue.pop(0)
                print 'processing from best Effort queue'
                
            yield hold,self,packet.packetSize/1000
            
            #if it is an email packet check
            packet.serviceTime = now() - packet.creationTime
            
                
            